package com.edu.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.edu.dao.UserComentsDao;
import com.edu.dao.impl.UserComentsDaoImpl;
import com.edu.entity.CommentDTO;
import com.edu.entity.ContentVote;
import com.edu.entity.UserComents;
import com.edu.service.UserComentsService;

public class UserComentsServiceImpl implements UserComentsService {
private UserComentsDao ucd = new UserComentsDaoImpl();
	@Override
	public List<CommentDTO> getAllUserComents(int sellerId,int loginUserId) {
		List<CommentDTO> listCdto = ucd.selectAllUserComents(sellerId);
//		System.out.println(listCdto);
		List<CommentDTO> listComment = new ArrayList<CommentDTO>();
		for (int i = 0; i < listCdto.size(); i++) {
			CommentDTO c = listCdto.get(i);
			System.out.println(loginUserId);
			CommentDTO cdto = ucd.selectComentsByUserId(loginUserId, c.getCommentId());
			cdto.setCommentId(c.getCommentId());
			listComment.add(cdto);
		}
		return listComment;
	}
	@Override
	public int getAllUserComentNums(int target_user_id) {
		// TODO Auto-generated method stub
		return ucd.selectAllUserComentNums(target_user_id);
	}
	@Override
	public CommentDTO getCommentsById(int userId, int sellerId, int commentId) {
		//根据用户id查出来需要的信息
		CommentDTO cDTO = new CommentDTO();
		cDTO = ucd.selectComentsByUserId(userId, commentId);
		if(cDTO==null) {
			return null;
		}
		int likeNums = ucd.likeOrDislikeNums(commentId, 1);
		int disLikeNums = ucd.likeOrDislikeNums(commentId, -1);
		cDTO.setLikeNums(likeNums);
		cDTO.setDislikeNums(disLikeNums);

		return cDTO;
	}
	@Override
	public int addCotentVote(ContentVote cv) {
		// TODO Auto-generated method stub
		return ucd.insertInto(cv);
	}
	@Override
	public ContentVote seleteContentVote(ContentVote cv) {
		// TODO Auto-generated method stub
		return ucd.seleteContentVote(cv);
	}
	@Override
	public int updateContentVote(ContentVote cv) {
		// TODO Auto-generated method stub
		return ucd.updateContentVote(cv);
	}
	@Override
	public int addComent(UserComents uc) {
		// TODO Auto-generated method stub
		return ucd.insetComent(uc);
	}

}
